<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.keywords" placeholder="关键字/id/题目标题" style="width: 200px;" class="filter-item"
        @keyup.enter.native="handleFilter" />
      <el-select v-model="listQuery.order" placeholder="排序规则" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in order" :key="index" :label="item" :value="index" />
      </el-select>
      <el-select v-model="listQuery.status" placeholder="按状态查询" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in status" :key="index" :label="item" :value="index" />
      </el-select>
      <el-select v-model="listQuery.role" placeholder="按房间类型" clearable style="width: 150px" class="filter-item">
        <el-option v-for="(item, index) in role" :key="index" :label="item" :value="index" />
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
    </div>
    <el-table :key="tableKey" v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员id" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员昵称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员手机号码" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.member_phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="房间状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status ==0">正常</span>
          <span v-if="scope.row.status ==1">过期</span>
          <span v-if="scope.row.status ==2">封禁</span>
        </template>
      </el-table-column>
      <el-table-column label="房间类型" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.role ==0">普通</span>
          <span v-if="scope.row.role ==1">队长</span>
          <span v-if="scope.row.role ==2">讲师</span>
        </template>
      </el-table-column>
      <el-table-column label="面试厅标题" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="面试厅描述" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.describe }}</span>
        </template>
      </el-table-column>
      <el-table-column label="售价" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.money}}</span>
        </template>
      </el-table-column>
      <el-table-column label="成员人数" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.member">
            <el-button size="small" type="primary" @click="member(scope.row)">{{ scope.row.member }}</el-button>
          </span>
          <span v-else>0</span>
        </template>
      </el-table-column>
      <el-table-column label="好评率" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.rank *100 }} %</span>
        </template>
      </el-table-column>
      <el-table-column label="好评数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_like }}</span>
        </template>
      </el-table-column>
      <el-table-column label="中评数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_medium }}</span>
        </template>
      </el-table-column>
      <el-table-column label="差评数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_hate }}</span>
        </template>
      </el-table-column>
      <el-table-column label="举报数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_report }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收藏数" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.number_collect }}</span>
        </template>
      </el-table-column>
      <el-table-column label="经度" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.x }}</span>
        </template>
      </el-table-column>
      <el-table-column label="纬度" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.y }}</span>
        </template>
      </el-table-column>
      <el-table-column label="添加日期" align="center">
        <template slot-scope="{ row }">
          {{ _date(row.create_time) }}
        </template>
      </el-table-column>

      <el-table-column label="操作" width="80" align="center">
        <template slot-scope="scope">
          <div>
            <span v-permission="['/library/answerEdit']">
              <el-button size="small" type="primary" @click="edit(scope.row)">编 辑</el-button>
              <!-- <el-button size="small" type="primary" @click="del(scope.row)">删 除</el-button> -->
            </span>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

    <el-dialog title="编辑面试厅" :visible.sync="show">
      <el-form>
        <el-form-item label="面试厅名称" label-width="150px">
          <el-input v-model="item.title" disabled />
        </el-form-item>
        <el-form-item label="面试厅状态" label-width="150px">
          <el-select v-model="item.status" placeholder="面试厅状态" clearable style="width: 150px" class="filter-item">
            <el-option label="正常" :value="0" />
            <el-option label="过期" :value="1" />
            <el-option label="封禁" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="房间售价" label-width="150px">
          <el-input v-model="item.money" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handle(item)">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="面试厅成员列表" :visible.sync="memberShow">
      <el-table :key="tableKey" v-loading="listLoading" :data="memberList" border fit highlight-current-row style="width: 100%;">
        <el-table-column label="ID" prop="id" sortable="custom" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="会员id" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.member_id }}</span>
          </template>
        </el-table-column>
        <el-table-column label="会员昵称" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.member_name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="会员手机号码" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.member_phone }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.status == 0">申请中</span>
            <span v-if="scope.row.status == 1">已加入</span>
            <span v-if="scope.row.status == 2">创建者</span>
          </template>
        </el-table-column>
        <el-table-column label="是否支付" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.pay == 0">未支付</span>
            <span v-if="scope.row.pay == 1">未支付</span>
          </template>
        </el-table-column>
        <el-table-column label="评价级别" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.like == 0">未评价</span>
            <span v-if="scope.row.like == 1">好评</span>
            <span v-if="scope.row.like == 2">中评</span>
            <span v-if="scope.row.like == 3">差评</span>
          </template>
        </el-table-column>
        <el-table-column label="花费金额" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.money }}</span>
          </template>
        </el-table-column>
        <el-table-column label="加入日期" align="center">
          <template slot-scope="{ row }">
            {{ _date(row.create_time) }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
  import {
    interviewList,
    interviewMemberList,
    interviewEdit
  } from '@/api/interview';
  import {
    addressList
  } from '@/api/config';
  import waves from '@/directive/waves';
  import Pagination from '@/components/Pagination';
  import permission from '@/directive/permission/index.js';
  import {
    dateHandle
  } from '@/api/dateHandle';
  import imageUpload from '@/components/Upload/image';

  export default {
    components: {
      Pagination,
      imageUpload
    },
    directives: {
      waves,
      permission,

    },
    data() {
      return {
        tableKey: 0,
        list: null,
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          cate_id: null,
          limit: 20,
          topic_id: 0,
        },
        item: {},
        order: {
          number_rank: '好评率',
          number_like: '好评数',
          number_medium: '中评数',
          number_hate: '差评数',
          number_comment: '评论数',
          number_collect: '收藏数',
          number_report: '举报数',
          money: '售价',
          id: '最新',
        },
        status: {
          0: '正常',
          1: '过期',
          2: '封禁'
        },
        role: {
          0: '普通房间',
          1: '队长房间',
          2: '讲师房间'
        },
        memberShow: false,
        memberList: null,
        show: false
      };
    },
    created() {
      this.getList()

    },
    methods: {
      _date(t) {
        return dateHandle('Y-m-d H:i:s', t)
      },

      handle() {
        interviewEdit(this.item).then(res => {
          if (res.code == 20000) {
            this.$message({
              type: 'success',
              message: res.msg
            });
            this.show = false
            this.getList()
          }
        })
      },
      member(item) {
        interviewMemberList({
          id: item.id
        }).then(res => {
          this.memberList = res.data
        })
        this.memberShow = true
      },
      edit(item) {
        this.item = item
        this.show = true
      },
      getList() {
        this.listLoading = true;
        interviewList(this.listQuery).then(res => {
          this.list = res.data.data;
          this.total = res.data.total;
          setTimeout(() => {
            this.listLoading = false;
          }, 0.3 * 1000);
        });
      },

    }
  };
</script>
